package com.service.admin.product.controller;

import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.CommonPageRep;
import com.service.core.rest.response.OneResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.enums.CommonStatusEnums;
import com.service.dao.enums.HrComboEnum;
import com.service.admin.framework.log.RequestLog;
import com.service.admin.product.controller.req.HashRateComboAddReq;
import com.service.admin.product.controller.req.HashRateComboPageReq;
import com.service.admin.product.controller.req.UpdateNumReq;
import com.service.admin.product.service.ProductHrComboService;
import com.service.utility.common.UUIDUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 算力套餐表
 *
 * @author xxxx
 * @email xxxx@qq.com
 * @date 2019-11-10 22:06:11
 */
@Slf4j
@Api(tags = "套餐相关产品")
@RestController
@RequestMapping("product-hr-combo")
public class ProductHrComboController extends BaseController {
    @Autowired
    private ProductHrComboService comboService;

    @ApiOperation("分页")
    @PostMapping("page")
    public PageResponse page(@RequestBody HashRateComboPageReq pageReq) {
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", pageReq, uuid);
        CommonPageRep result = comboService.page(pageReq);
        log.info("请求结束： UUID:{}", uuid);
        return successQueryPageResponse(result);
    }


    @ApiOperation("算力商品选项")
    @GetMapping("item")
    public OneResponse item(){
        return successQueryOneResponse(comboService.items());
    }

    @RequestLog("创建算力套餐")
    @ApiOperation("创建")
    @PostMapping("create")
    public BaseResponse page(@RequestBody @Validated HashRateComboAddReq addReq) {
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", addReq, uuid);
        comboService.create(addReq);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @RequestLog("详情")
    @GetMapping("detail/{id}")
    public OneResponse update(@PathVariable("id") Integer id) {
        return successQueryOneResponse(comboService.detail(id));
    }

    @ApiOperation("更新")
    @PostMapping("update/{id}")
    public BaseResponse update(@PathVariable("id") Integer id, @RequestBody @Validated HashRateComboAddReq addReq) {
        String uuid = UUIDUtil.randomUUID();
        addReq.setId(id);
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", addReq, uuid);
        comboService.modifyCombo(addReq);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @ApiOperation("上架产品")
    @PostMapping("shelf/{id}")
    public BaseResponse shelfCombo(@ApiParam @PathVariable("id") Integer id) {
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", id, uuid);
        comboService.updateComboStatus(id, HrComboEnum.PUT_AWAY);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @ApiOperation("下架产品")
    @PostMapping("lower/{id}")
    public BaseResponse lowerCombo(@ApiParam @PathVariable("id") Integer id) {
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", id, uuid);
        comboService.updateComboStatus(id, HrComboEnum.TAKE_OFF);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @ApiOperation("删除")
    @PostMapping("delete/{id}")
    public BaseResponse delete(@PathVariable("id") Integer id) {
        String uuid = UUIDUtil.randomUUID();
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", id, uuid);
        comboService.updateComboStatus(id, CommonStatusEnums.DELETE);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @ApiOperation("修改库存")
    @PostMapping("update/stock/{id}")
    public BaseResponse updateStock(@PathVariable("id") Integer id, @RequestBody @Validated UpdateNumReq numReq) {
        String uuid = UUIDUtil.randomUUID();
        numReq.setId(id);
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", numReq, uuid);
        comboService.updateStockNum(numReq);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @ApiOperation("修改会员购买数量")
    @PostMapping("update/buy-num/{id}")
    public BaseResponse updateBuyNum(@PathVariable("id") Integer id, @RequestBody @Validated UpdateNumReq numReq) {
        String uuid = UUIDUtil.randomUUID();
        numReq.setId(id);
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", id, uuid);
        comboService.updateBuyNum(numReq);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }

    @ApiOperation("修改起购数量")
    @PostMapping("update/min-buy-num/{id}")
    public BaseResponse updateMinBuyNum(@PathVariable("id") Integer id, @RequestBody @Validated UpdateNumReq numReq) {
        String uuid = UUIDUtil.randomUUID();
        numReq.setId(id);
        log.info("请求开始 Msg: 请求参数：{}，UUID:{}", id, uuid);
        comboService.updateMinBuyNum(numReq);
        log.info("请求结束： UUID:{}", uuid);
        return successSaveBaseResponse();
    }




}
